#pragma once
#include "Actor.h"
#include "RenderToTexture.h"

namespace mini
{
	enum  LightType
	{
		Direction = 0,
		Point     = 1,
	};
	struct LightColor 
	{
		CPoint3F position;
		CPoint4F mDiffuseColor;
	};

	class CLightActor : public CActor
	{
	public:
		CLightActor();
		virtual ~CLightActor();
		virtual void setPosition(CVector pt, bool bUpdate = false) override;
		virtual void setScale(CVector scale, bool bUpdate = false) override;

		void setSampler(ID3D11SamplerState* pSampler);
		bool createDepthTexture(int width, int height);
		void setProjectMatrix(float fNear, float fFar);
		void setDirection(const CPoint4F& dir);
		void setAmbientColor(const CPoint4F& color);
		void setDiffuseColor(const CPoint4F& color);
		void setSpecularColor(const CPoint4F& color);
		void setSpecularPower(float power);

		CPoint4F getAmbientColor();
		CPoint4F getDiffuseColor();
		CPoint4F getSpecularColor();
		CPoint4F getDirection();
		CPoint4F getPosition();
		float	 getSpecularPower();
		
		void	effectActor(CActor* pActor);
		void	unEffectActor(CActor* pActor);
		LightType getLightType();
		void setLightType(LightType type);
		std::string getLightName() const;
		void setLightName(const std::string& szName);
		float* getLightData();
		int getLigteDataLength();

		int getRegister();
		int getPackoffset();
		void setUpdateData( void* pData);
		CMatrix& GetViewMatrix();
		CMatrix& GetProjectionMatrix();
		CRenderToTexture* getRenderToTexturePtr() const;

	private:
		bool _checkEffectActor(CActor* pActor);
		void _checkEffectActors();
	
	
	private:
		int mRegister = 0;
		int mPackoffset = 0;
		D3DXMATRIX mProjectionMatrix;
		D3DXMATRIX mOrthoMatrix;
		LightType				mLightType = LightType::Direction;
		std::list<CActor*>		mEffectActors;
		CRenderToTexture*		mpDepthTexture = nullptr;
		int mTextureWidth = 0;
		int mTextureHeight = 0;
		CPoint4F m_ambientColor;
		CPoint4F m_diffuseColor;
		CPoint4F m_specularColor;
		CPoint4F m_direction;
		float* m_specularPower = nullptr;
		CMatrix m_viewMatrix;
		CMatrix m_projectionMatrix;
		bool	mUpdateViewMatrix = true;
 	};
}
